//
//  BarView.m
//  AVPLayer3
//
//  Created by dllo on 15/10/9.
//  Copyright © 2015年 liuchunling. All rights reserved.
//

#import "BarView.h"

@implementation BarView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        [self setupViews];
    }
    return self;
}

- (void)setupViews
{
    
    //缓冲进度条
    self.playProgress = [[UIProgressView alloc] init];
    [self.playProgress setProgressTintColor:[UIColor redColor]];
    [self addSubview:self.playProgress];
    
    //滑动进度条
    self.playSlider = [[UISlider alloc] init];
    [self.playSlider setThumbImage:[UIImage imageNamed:@"ball.png"] forState:UIControlStateNormal];
    [self.playSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    
    [self addSubview:self.playSlider];
 
    //时间
    self.totalTimeLabel = [[UILabel alloc] init];
    self.totalTimeLabel.font = [UIFont systemFontOfSize:14];
    self.totalTimeLabel.textAlignment = NSTextAlignmentCenter;
    self.totalTimeLabel.textColor = [UIColor whiteColor];
    [self addSubview:self.totalTimeLabel];
    
    //缓存进度条
    UIGraphicsBeginImageContextWithOptions((CGSize){ 2, 2 }, NO, 0.0f);
    UIImage *transparentImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.playSlider setMinimumTrackTintColor:[UIColor orangeColor]];
    [self.playSlider setMaximumTrackImage:transparentImage forState:UIControlStateNormal];
    
    
    //播放按钮
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.playButton addTarget:self action:@selector(playButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.playButton setBackgroundColor:[UIColor clearColor]];
    [self.playButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
    [self addSubview:self.playButton];
    
}




- (void)sliderAction:(UISlider *)slider
{
    [self.delegate sliderActionWith:slider];
}

- (void)playButtonAction:(UIButton *)button
{
    [self.delegate playButtonActionWith:button];
}


@end
